<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
//Get selected lesson.
function getLesson(val){
	window.location.href="addQuestion.do?lId="+val;

}
//Show answer according to type.
function show(val){
	document.getElementById("ck1").checked=true;
	document.getElementById("ra1").checked=true;
	
	if(val=="s"){
		sOption.style.display="";
		mOption.style.display="none";
	}else if(val=="m"){
		sOption.style.display="none";
		mOption.style.display="";		
	}
}

function check(form){

	if(form.pId.value==""){
			alert("请选择套题!");
			form.subject.focus();
			return false;
	}
	if(form.subject.value==""){
		alert("请输入考试题目名称!");
		form.subject.focus();
		return false;
	}
	if(form.optionA.value==""){
		alert("请输入A选项");
		form.optionA.focus();
		return false;
	}
	if(form.optionB.value==""){
		alert("请输入B选项");
		form.optionB.focus();
		return false;
	}
	if(form.optionC.value==""){
		alert("请输入C选项");
		form.optionC.focus();
		return false;
	}
	if(form.optionD.value==""){
		alert("请输入D选项");
		form.optionD.focus();
		return false;
	}
}


</script>
</head>
<body onload="show('s')">
<form action="saveQuestion.do" method="post" onsubmit="return check(this)">
<input name="qId" value="${question.id }" type="hidden"/>
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
<tr>
    <td height="30" align="left" style="padding:5px;">所属课程：</td>
    <td align="left">
		<select name="lId" onchange="getLesson(this.value)">
		<c:forEach items="${lessons }" var="l">
		<c:if test="${lesson.id==l.id }">
		<option value="${l.id }" selected="selected">${l.name }</option>
		</c:if>
		<c:if test="${lesson.id!=l.id }">
		<option value="${l.id }">${l.name }</option>
		</c:if>
		</c:forEach>
		</select>
    </td>
</tr>
<tr>
    <td height="30" align="left" style="padding:5px;">所属套题：</td>
    <td align="left" id="whichTaoTi">
    	<select name="pId">
    	<c:forEach items="${lesson.papers }" var="p">
    	<option value="${p.id }">${p.name }</option>
    	</c:forEach>
    	</select>
    </td>
</tr>
<tr align="center">
    <td height="30" align="left" style="padding:5px;">考试题目：</td>
    <td align="left">
      	<input name="subject" value="${question.subject }"> *
	</td>
</tr>
<tr>
    <td height="30" align="left" style="padding:5px;">试题类型：</td>
    <td align="left">
	 	<select name="type" onchange="show(this.value)"> 
	 	<option value="s" selected="selected">单选题</option>
	 	<option value="m">多选题</option>
	 	</select>
    </td>
</tr>	
<tr align="center">
    <td height="30" align="left" style="padding:5px;">选项A：</td>
    <td align="left">
      	<input name="optionA"> *
	</td>
</tr>
<tr align="center">
    <td  height="30" align="left" style="padding:5px;">选项B：</td>
    <td  align="left">
      	<input name="optionB"> *
	</td>
</tr>
<tr align="center">
    <td height="30" align="left" style="padding:5px;">选项C：</td>
    <td align="left">
      	<input name="optionC"> *
	</td>
</tr>
<tr align="center">
    <td  height="30" align="left" style="padding:5px;">选项D：</td>
    <td  align="left">
      <input name="optionD"> *
	  </td>
    </tr>
    
    <tr align="center">
    	<td height="30" align="left" style="padding:5px;">正确答案：</td>
    	<td align="left" id="mOption">
	    	<input type="checkbox" id="ck1" name="answers" value="A">A
	    	&nbsp;&nbsp;
	    	<input type="checkbox" id="ck2" name="answers" value="B">B
	    	&nbsp;&nbsp;
	    	<input type="checkbox" id="ck3" name="answers" value="C">C
	    	&nbsp;&nbsp;
	    	<input type="checkbox" id="ck4" name="answers" value="D">D
	  	</td>	
	  	<td align="left" id="sOption">
	  		<input type="radio" id="ra1" name="answer" value="A">A
	  		&nbsp;&nbsp;
	  		<input type="radio" id="ra2" name="answer" value="B">B
	  		&nbsp;&nbsp;
	  		<input type="radio" id="ra3" name="answer" value="C">C
	  		&nbsp;&nbsp;
	  		<input type="radio" id="ra4" name="answer" value="D">D
	  	</td>
	</tr>
   	<tr>
   		<td colspan="2"><input type="submit" value="保存"/>
   		<input type="reset" value="取消"/></td>
		
   	</tr>
</table>
</form>
</body>
</html>